package com.niiwoo.civet.account.service.local.openAccount2.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.niiwoo.civet.account.dao.entity.OpenAccountRecord;
import com.niiwoo.civet.account.enums.OpenAccountRecordStatusEnum;
import com.niiwoo.civet.account.enums.OpenAccountWayEnum;
import com.niiwoo.civet.account.service.local.notify.PersonalizedNotifyAccountLocalService;
import com.niiwoo.civet.account.service.local.openAccount2.dto.OpenAccountEvent;
import com.niiwoo.tripod.lanmao.enums.UserRoleEnum;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class PersonalizedNotifyListener implements OpenAccountListener {

    @Autowired
    private PersonalizedNotifyAccountLocalService personalizedNotifyAccountLocalService;
    
    @Override
    public void handle(OpenAccountEvent event) {
    	OpenAccountRecord record = event.getRecord();
        if (!UserRoleEnum.enumOf(record.getAccountRole()).equals(UserRoleEnum.INVESTOR)) {
            return;
        }
        log.info("###个性化通知-用户开通投资存管帐户###推送信息，UserId:{}", record.getUserId());
        personalizedNotifyAccountLocalService.pushOpenInvestmentSuccessMessageToUser(record.getUserId());
        log.info("###个性化通知-用户开通投资存管帐户###推送信息成功，UserId:{}", record.getUserId());
    }

    @Override
    public boolean isExpectStatus(OpenAccountRecordStatusEnum status) {
    	return OpenAccountRecordStatusEnum.SUCCESS.equals(status);        
    }

    @Override
    public boolean isInterestedOpenAccountWay(OpenAccountWayEnum way) {
        return true;
    }
}